package com.quan.commons.exception;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import com.quan.commons.pojo.JSONResult;
import com.quan.commons.utils.WebUtils;

/**
 * 统一异常处理，返回JSON格式数据
 * 
 * @author yhaoquan
 *
 */
@ControllerAdvice
public class WebExceptionHandler {

	@ExceptionHandler(Exception.class)
	public @ResponseBody Object handleControllerException(HttpServletRequest request, HttpServletResponse response, Throwable e) {
		//处理Ajax请求异常
		
		//返回JSON格式数据
		return JSONResult.errorException(WebUtils.getStatus(request).value(), e.getMessage());
	}
	
}
